var express = require('express');
var router = express.Router();
const { checkAuth } = require("../../middleware/token")
const { ACCESS_KEY, REFRESH_KEY } = require("../../config/keys")
let {gomodel,goodcarmodel,shopmodel}=require('../../model/model')
/* GET home page. */
router.get('/showgoods',checkAuth(ACCESS_KEY),async(req, res)=>{
  let gols=await gomodel.find()
  res.send({
    code:200,
    gols
  })
});
router.get('/showcar',async(req, res)=>{
  let gcar=await goodcarmodel.find()
  res.send({
    code:200,
    gcar  
  })
});

//收藏
router.put('/addscuser',async(req,res)=>{
  let {id} =req.query
  await gomodel.updateOne({_id:id},req.body)
  console.log(req.body);
  res.send({
    code:200,
    msg:'添加成功'
  })
})
//添加至购物车
router.post('/addcar',async(req,res)=>{
  await goodcarmodel.create(req.body)
  res.send({
    code:200,
    msg:'添加成功'
  })
})
//店铺
router.get('/showshop',async(req, res)=>{
  let gshop=await shopmodel.find()
  res.send({
    code:200,
    gshop
  })
});
//热度店铺
router.put('/addhot',async(req,res)=>{
  let {id} =req.query
  await shopmodel.updateOne({_id:id},{$set:{hot:req.body.hot++}})
  console.log(req.body);
});
module.exports = router;
